<?php
class UsersController extends AppController {
	var $name = 'Users';
	var $components = array('Auth');

	function beforeFilter() {
		$this->Auth->allow('register');
		$this->Auth->loginError = "登录邮箱或者密码有问题，是不是输错了";
		$this->Auth->fields = array(
			'username' => 'email',
			'password' => 'password'
		);
	}

    function me() {
    }

    function bindSNS() {
    	App::import('Vendor', 'SinaWeibo', array('file' => 'sinaweibo'.DS.'saet2.ex.class.php'));
        //SaeTOAuth oauth = new SaeTOAuth(Constant('SINA_KEY'), Constant('SINA_SECRET'));
    }

	function login() {
		if ($this->Session->read('Auth.User')) {
			$this->redirect('/jobs/', null, false);
		}
	}

	function logout() {
		$this->redirect($this->Auth->logout());
	}

	function register() {
        $this->set('title_for_layout', '成为我们的注册用户 - 推合互联');
		if ($this->data) {
		//pr($this->data);
			if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) {
				$this->User->create();
				if ($this->User->save($this->data)) {
					$this->Session->setFlash('注册成功，登录后就可以发布职位了！');
					$this->redirect(array('action' => 'login'));
				}
			}
		}
	}
}
?>
